package com.dq.Controller;

import com.dq.Pojo.Result;
import com.dq.Pojo.Sharecourse;
import com.dq.Service.ShareService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/share")
public class ShareController {
    @Autowired
    private ShareService shareService;
    //分配课程记录添加
    @PostMapping("/add")
    public Result add(@RequestBody Sharecourse sharecourse){
        Sharecourse s=shareService.findById(sharecourse.getClassid(),sharecourse.getCourseid());
        if (s==null){
            shareService.add(sharecourse);
            return Result.success();
        }else {
            return Result.error("此班级课程已分配!!!");
        }
    }
    //分页查询
    @GetMapping("/findAll")
    public  Result<PageInfo<Sharecourse>> findAll(@RequestParam Integer pageNum,
                                                  @RequestParam Integer pageSize,
                                                  @RequestParam String courseid,
                                                  @RequestParam String classid,
                                                  @RequestParam String teaid){
        PageInfo<Sharecourse> sharecoursePageInfo=shareService.findAll(pageNum,pageSize,courseid,classid,teaid);
        return Result.success(sharecoursePageInfo);
    }
    @DeleteMapping("/delete")
    public  Result delete(@RequestParam Integer id){
        shareService.delete(id);
        return Result.success();
    }

    //获取课程信息list(学生)
    @GetMapping("/getStulist")
    public Result getlist(@RequestParam Integer id){
        List<Sharecourse> sharecourseList=shareService.findBystuid(id);
        return Result.success(sharecourseList);
    }
    //获取课程信息list(教师)
    @GetMapping("/getTealist")
    public Result getlist1(@RequestParam Integer id){
        List<Sharecourse> sharecourseList=shareService.findByteaid(id);
        return Result.success(sharecourseList);
    }

}
